home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_02_11
/
2n11012a
< prev
next >
Wrap
Text File
|
1991-09-08
|
2KB
|
101 lines
#include <stdio.h>
#include "memory.hpp"
main()
{
unsigned **jj;
unsigned i,k;
unsigned sz;
while (1)
{
printf ("Enter default size, no of items");
scanf("%d %d",&sz,&k);
InitMem(sz);
jj = new unsigned *[k];
for (i=0;i<k;i++)
{
jj[i] = new unsigned;
}
for (i=0; i<k; i++)
{
if (jj[i] != NULL)
*(jj[i]) = i;
}
for (i=0; i<k; i++)
{
if (jj[i] != NULL)
printf("value = %d pointer= %p long= %d\n",\
*(jj[i]),jj[i],(long)(jj[i]) );
}
printf("pointer= %p long=%d\n",jj,(long)jj);
float *f = new float;
if (f != NULL)
*f = 123456.7890;
printf("old pointer=%p, new pointer=%p, new value=%f\n",\
jj[2],f,*f);
delete f;
f = NULL;
for (i=0;i<k;i++)
{
delete jj[i];
jj[i] = NULL;
}
delete jj;
jj = NULL;
delete f;
f = NULL;
jj = new unsigned *[k];
for (i=0;i<k;i++)
{
jj[i] = new unsigned;
}
for (i=0; i<k; i++)
{
if (jj[i] != NULL)
*(jj[i]) = i;
}
for (i=0; i<k; i++)
{
if (jj[i] != NULL)
printf("value = %d pointer= %p long= %d\n",\
*(jj[i]),jj[i],(long)(jj[i]) );
}
printf("pointer= %p long=%d\n", jj, (long)jj);
for (i=0;i<k;i++)
{
delete jj[i];
jj[i] = NULL;
}
delete jj;
jj = NULL;
EndMem();
}
}